{% extends "base.html" %}
{% block content %}
<section class="hero">
    <h1 class="title">AI效能分析报告</h1>
    <p class="subtitle">基于当前数据生成的智能分析报告</p>
</section>

<section class="data-section">
    <div class="report-container" id="aiReportContent">
        <div class="placeholder-section">
            <div class="placeholder-content">
                <span class="placeholder-icon">🤖</span>
                <p>正在加载AI分析报告...</p>
            </div>
        </div>
    </div>
</section>

<script>
document.addEventListener('DOMContentLoaded', function() {
    const aiReportContent = document.getElementById('aiReportContent');
    const aiResult = localStorage.getItem('aiAnalysisResult');
    
    if (aiResult) {
        const analysis = JSON.parse(aiResult);
        
        aiReportContent.innerHTML = `
            <div class="analysis-header">
                <h3>📊 效能分析总结</h3>
                <p class="analysis-time">生成时间: ${analysis.timestamp}</p>
            </div>
            
            <div class="analysis-content">
                <div class="analysis-text">
                    ${analysis.summary.replace(/\n/g, '<br>')}
                </div>
                
                <div class="analysis-stats">
                    <h4>📈 数据统计</h4>
                    <p>分析项目数量: ${analysis.data_summary.total_projects}</p>
                    <p>延期需求数量: ${analysis.data_summary.delayed_count}</p>
                    <p>工作量统计人员: ${analysis.data_summary.workload_count}</p>
                </div>
            </div>
            
            <div class="analysis-actions">
                <button class="action" onclick="window.location.href='/performance'">返回数据页面</button>
                <button class="action subtle" onclick="regenerateAnalysis()">重新分析</button>
            </div>
        `;
    } else {
        aiReportContent.innerHTML = `
            <div class="placeholder-section">
                <div class="placeholder-content">
                    <span class="placeholder-icon">📊</span>
                    <p>暂无AI分析报告，请先在数据页面点击"AI分析"按钮生成</p>
                    <button class="action" onclick="window.location.href='/performance'">前往数据页面</button>
                </div>
            </div>
        `;
    }
});

function regenerateAnalysis() {
    localStorage.removeItem('aiAnalysisResult');
    window.location.href = '/performance';
}
</script>

<style>
.analysis-header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #e0e0e0;
}

.analysis-time {
    color: #666;
    font-size: 0.9rem;
}

.analysis-content {
    line-height: 1.8;
}

.analysis-text {
    background: #f8f9fa;
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 2rem;
}

.analysis-stats {
    background: #e8f5e8;
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 2rem;
}

.analysis-stats h4 {
    margin-top: 0;
    color: #2e7d32;
}

.analysis-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
}
</style>
{% endblock %}